#!/usr/bin/env python
# coding=utf-8
"""胜率0.5, 每天都玩m局直到赢得一局, n天之后总体胜率. 结果证明还tm得是0.5, fuck"""
import argparse
import random


def main():
    arg_parser = argparse.ArgumentParser(description="胜率1/2, 每天都玩m局直到赢得一局, n天之后总体胜率.")
    arg_parser.add_argument("nday", type=int, default=1, help="天数")
    args = arg_parser.parse_args()

    num_win = 0
    num_lose = 0
    num_day = 0

    while num_day < args.nday:
        num_day, num_win, num_lose = a_round(num_day, num_win, num_lose)
        num_day += 1

    print("After %i days of fighting, we total play %i times, win %i times, lose %i times, rate %f" % (num_day,
          (num_win + num_lose), num_win, num_lose, 1.0 * num_win / (num_win + num_lose)))


def a_round(num_day, num_win, num_lose):
    # print("The %i day begin" % (num_day + 1))
    i = 0
    while True:
#        is_win = random.choice([True, False])
        r = random.random()
        is_win = r <= 0.6
        i += 1
        if is_win:
            num_win += 1
            # print("The %i day end, play %i times" % (num_day+1, i))
            return num_day, num_win, num_lose
        else:
            num_lose = num_lose + 1


if __name__ == '__main__':
    main()
